<template>
  <a-layout-header :class="[headerTheme, 'admin-header']">
    <div :class="['admin-header-wide', layout, pageWidth]" style="display: flex;justify-content: space-between;">
      <div v-if="isMobile || layout === 'head'" :class="['logo', isMobile ? null : 'pc', headerTheme]" style="margin-right: auto;margin-left: 15px;cursor: auto;">
        <img height="38" src="@/assets/logo/logoNmae2.png" />
        <!-- <h1 v-if="!isMobile">{{systemName}}</h1> -->
      </div>
      <a-icon v-if="(layout !== 'head' && !isMobile)" class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="toggleCollapse"/>
      <div id="" style="flex: 1;display: flex;justify-content: center;">
          <div v-if="layout !== 'side' && !isMobile" class="admin-header-menu" >
            <!-- <i-menu class="head-menu" theme="dark" mode="horizontal" :options="menuData" @select="onSelect"/> -->
            <div class="" style="color: #fff;display: flex;justify-content: center;">
                <span v-for="res,i in menuData.filter(e=>!e.meta.invisible)" :key="i" style="padding: 0 15px;white-space: nowrap;cursor: pointer;" @click="goPage(res)" :style="$route.path.indexOf(res.fullPath) != -1?'color: #40E6FE':''">{{res.name}}</span>
            </div>
          </div>
      </div>
      <div :class="['admin-header-right', headerTheme]" style="margin-left: auto;">
          <!-- <header-search class="header-item" @active="val => searchActive = val" /> -->
          <div>{{time}}</div>
          <!-- <header-notice class="header-item"/> -->
          <HeaderAvatar class="header-item"/>
          <!-- <a-dropdown class="lang header-item">
            <div>
              <a-icon type="global"/> {{langAlias}}
            </div>
            <a-menu @click="val => setLang(val.key)" :selected-keys="[lang]" slot="overlay">
              <a-menu-item v-for=" lang in langList" :key="lang.key">{{lang.key.toLowerCase() + ' ' + lang.name}}</a-menu-item>
            </a-menu>
          </a-dropdown> -->
      </div>
    </div>
  </a-layout-header>
</template>

<script>
import HeaderSearch from './HeaderSearch'

// import HeaderNotice from './HeaderNotice'
import HeaderAvatar from './HeaderAvatar'
import IMenu from '@/components/menu/menu'
import {mapState, mapMutations} from 'vuex'

export default {
  name: 'AdminHeader',
  components: {IMenu, HeaderAvatar, HeaderSearch},
  props: ['collapsed', 'menuData'],
  data() {
    return {
      langList: [
        {key: 'CN', name: '简体中文', alias: '简体'},
        {key: 'HK', name: '繁體中文', alias: '繁體'},
        {key: 'US', name: 'English', alias: 'English'}
      ],
      searchActive: false,
      time:''
    }
  },
  computed: {
    ...mapState('setting', ['theme', 'isMobile', 'layout', 'systemName', 'lang', 'pageWidth']),
    headerTheme () {
      if (this.theme.mode == 'dark' && !this.isMobile) {
        return 'light'
      }
      return this.theme.mode
    },
    langAlias() {
      let lang = this.langList.find(item => item.key == this.lang)
      return lang.alias
    },
    menuWidth() {
      const {layout, searchActive} = this
      const headWidth = layout === 'head' ? '100% - 188px' : '100%'
      const extraWidth = searchActive ? '200px' : '0px'
      return `calc(${headWidth} - ${extraWidth})`
    }
  },
  created(){
      this.getTime()
      console.log(this.$props.menuData);
  },
  methods: {
      goPage(res){
          console.log(res);
          this.$router.push(res.fullPath)
      },
    getTime(){
      const date = new Date()
      const Y = date.getFullYear()
      const M = date.getMonth() + 1
      const D = date.getDate()
      const w = date.getDay()
      const h = date.getHours()
      const m = date.getMinutes()
      const s = date.getSeconds()
      const weekArr = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六']
      this.time = `${Y}-${M<10?'0'+M:M}-${D<10?'0'+D:D}\u00A0\u00A0${weekArr[w]}\u00A0\u00A0${h<10?'0'+h:h}:${m<10?'0'+m:m}:${s<10?'0'+s:s} `
      // console.log(`获取时间:${this.time} \r 下次获取时间:${60-s}s后`);
      setTimeout(()=>{
        this.getTime()
      },1000)
    },
    toggleCollapse () {
      this.$emit('toggleCollapse')
    },
    onSelect (obj) {
      this.$emit('menuSelect', obj)
    },
    ...mapMutations('setting', ['setLang'])
  }
}
</script>

<style lang="less" scoped>
@import "index";
</style>
<style type="text/css">
    .ant-menu-dark .ant-menu-item, .ant-menu-dark .ant-menu-item-group-title, .ant-menu-dark .ant-menu-item > a {
        color: #fff;
        opacity: .8;
    }
</style>